<?php

namespace App;

use Illuminate\Foundation\Auth\User as AuthUser;

class AdminUser extends AuthUser
{
    //
    protected $rememberTokenName = "";

    //用户有哪些角色

    public function role()
    {
        return $this->belongsToMany('App\AdminRole','admin_role_user','user_id','role_id')->withPivot(["user_id","role_id"]);
    }

    //是否有某个或某些juese
    public function isInRoles($roles)
    {
        return !!$roles->intersect($this->role)->count();
    }

    //给用户封面配角色
    public function assignRole($role)
    {
        return $this->role()->save($role);
    }

    //删除用户角色
    public function delRole($role)
    {
        return $this->role()->detach($role);
    }

    //用户是否有权限

    public function hasPermission($permission)
    {
        return $this->isInRoles($permission->role);
    }

}
